﻿@model PhoneBilling.Models.Report8Model
@{
    ViewBag.Title = "长途统计";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.async.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.edit.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Content/js/jquery.treeview.sortable.js")"></script>
<link href="@Url.Content("~/Content/js/jquery.treeview.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $(document).ready(
function () {

    $("#date1").ligerDateEditor({ showTime: true, label: '开始日期', initValue: '@Model.开始日期.ToString("yyyy-MM-dd HH:mm")', format: "yyyy-MM-dd hh:mm" });
    $("#date2").ligerDateEditor({ showTime: true, label: '结束日期', initValue: '@Model.结束日期.ToString("yyyy-MM-dd HH:mm")', format: "yyyy-MM-dd hh:mm" });
}
);
</script>
@{
    System.Text.StringBuilder sb = new System.Text.StringBuilder();
    for (int i = 0; i < Model.DepartmentList.Count; i++)
    {
        var department = Model.DepartmentList[i];
        if (i == 0)
        {
            sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Department',ulevel:'0' ", department.名称.Trim(), department.ID));
        }
        else
        {
            sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Department',ulevel:'0' ", department.名称.Trim(), department.ID));
        }

        if (department.分组List.Count > 0)
        {
            sb.Append(",children: [");

            for (int j = 0; j < department.分组List.Count; j++)
            {
                var group1 = department.分组List[j];
                if (j == 0)
                {
                    sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'1' ", group1.名称.Trim(), group1.ID));
                }
                else
                {
                    sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'1' ", group1.名称.Trim(), group1.ID));
                }

                if (group1.分组List.Count > 0)
                {
                    sb.Append(",children: [");

                    for (int k = 0; k < group1.分组List.Count; k++)
                    {
                        var group2 = group1.分组List[k];
                        if (k == 0)
                        {
                            sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'2' ", group2.名称.Trim(), group2.ID));
                        }
                        else
                        {
                            sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'2' ", group2.名称.Trim(), group2.ID));
                        }

                        if (group2.分组List.Count > 0)
                        {
                            sb.Append(",children: [");

                            for (int l = 0; l < group2.分组List.Count; l++)
                            {
                                var group3 = group2.分组List[l];
                                if (l == 0)
                                {
                                    sb.Append(string.Format("{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'3' ", group3.名称.Trim(), group3.ID));
                                }
                                else
                                {
                                    sb.Append(string.Format(",{{ text:'{0}', uid:'{1}',utype:'Group',ulevel:'3' ", group3.名称.Trim(), group3.ID));
                                }

                                sb.AppendLine("}");

                            }

                            sb.Append("]");
                        }

                        sb.AppendLine("}");

                    }

                    sb.Append("]");
                }

                sb.AppendLine("}");

            }

            sb.Append("]");
        }

        sb.AppendLine("}");

    }

    string data = sb.ToString();
}
@using (Html.BeginForm())
{
    <div class="report">
        <div class="system_contain_group col25">
            <h3 class="title">
                请选择部门或者分组</h3>
            <div class="system_scroll_container">
                <ul id="tree" />
            </div>
        </div>
        <div class="system_contain_group col75">
            <h3 class="title">
                其他条件</h3>
            @Html.HiddenFor(m => m.SelectItem, new { id = "SelectItem" })
            @Html.HiddenFor(m => m.IsExport, new { @class = "export" })
            <div class="system_input_contain">
                @Html.TextBox("开始日期", Model.开始日期, new { @id = "date1" })
            </div>
            <div class="system_input_contain">
                @Html.TextBox("结束日期", Model.结束日期, new { @id = "date2" })
            </div>
            <div class="system_input_contain">
                <input type="button" id="btnSearch" value="查询" />
                <input type="button" id="btnImport" value="导出Excel" />
                @*            <input type="submit" value="查询" class="input-submit" onclick="searchClick()" />
            <input type="submit" value="导出Excel" class="input-submit" onclick="exportClick()" />*@
            </div>
        </div>
    </div>
}
<script type="text/javascript">
    var tree;
    $(document).ready(function () {
        tree = $("#tree").ligerTree({ checkbox: false, parentIcon: null, childIcon: null, checkbox :true,
            data: [@Html.Raw(data)]});
        tree.collapseAll();
        $("#btnSearch").ligerButton(
        {
            click: function () {
                searchClick();
            }
        });
        $("#btnImport").ligerButton(
        {
            click: function () {
                exportClick();
            }
        });
     });

    function beforeSubmit() {
        var str = "";
        var list = tree.getChecked();
        
        for (var i = 0; i < list.length; i++) {
            if(list[i].data.utype == "Group")
            {
            if (str == "")
            {
                str += list[i].data.uid;
                }
            else
            {
                str += "!" + list[i].data.uid;
                }
            }
        }
        
        $("#SelectItem").attr("value", str);
    }

    function exportClick() {
        $(".export").val("True");
        beforeSubmit();
        $("form").submit();
    }

    function searchClick() {
        $(".export").val("False");
        beforeSubmit();
        $("form").submit();
    }
</script>
